﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HsTec.Mobile.Green.SqlServerDAL;
using Baimasoft.FrameWork.Base;
using Baimasoft.Web.UI;

public partial class BaseData_MachineRoomForm : Baimasoft.Web.UI.PageFormTop
{
    Area area = new Area();
    Machineroom MyMR = new Machineroom();

    #region 重写方法
    /// <summary>
    /// 绑定区域信息
    /// </summary>
    protected override void BindDDLData()
    {
        ddlRegionid.DataSource = area.GetAreaInfos(string.Empty);
        ddlRegionid.DataBind();
        ddlRegionid.Items.Insert(0, "全部");
        ddlRegionid.Items[0].Value = "0";

    }

    /// <summary>
    /// 初始化表单信息
    /// </summary>
    protected override void InitForm()
    {
        if (!Page.IsPostBack)
        {
            try
            {
                string sEditStatus = this.Request.QueryString["EditStatus"].ToString().Trim();
                if (sEditStatus == "2")
                {
                    string sID = this.Request.QueryString["ID"].ToString().Trim();
                    DataTable MyDT = MyMR.GetMachineRooms(" mroom_id = '" + sID + "' ");
                    foreach (DataRow dr in MyDT.Rows)
                    {
                        ddlRegionid.Text = dr["region_id"].ToString().Trim();
                        this.txtMroomName.Text = dr["mroom_name"].ToString().Trim();
                        this.txtMroomSeq.Text = dr["mroom_seq"].ToString().Trim();

                        this.mroom_memo.Text = dr["mroom_memo"].ToString().Trim();
                    }
                }
                else
                {
                }
            }
            catch
            {
            }
        }
    }
    /// <summary>
    /// 保存数据
    /// </summary>
    protected override void SavaData()
    {
        try
        {
            string sid = "";

            if (this.Request.Params["ID"] != null)
            {
                sid = this.Request.Params["ID"].Trim();
            }
            else
            {
                sid = "-1";
            }

            int iRegionId = int.Parse(this.ddlRegionid.SelectedValue);//区域ID
            string sMroomNamee = this.txtMroomName.Text;//机房名称
            int iMroomSeq = int.Parse(this.txtMroomSeq.Text);//排序

            string smroom_memo = mroom_memo.Text.ToString().Trim();

            DateTime DAddtime = DateTime.Now.AddDays(0);

            string sEditStatus = this.Request.QueryString["EditStatus"].ToString().Trim();
            if (sEditStatus == "1")
            {
                int iback = MyMR.InsertMachineRoomInfo(iRegionId, sMroomNamee, "", 0, DAddtime, iMroomSeq, "1", smroom_memo);
                if (iback > 0)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存成功!');location.href='MachineRoomManage.aspx';</script>");
                    return;
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存失败!');</script>");
                    return;
                }
            }
            else
            {
                int iback = 0;
                try
                {
                    iback = MyMR.UpdateMachineRoomInfo(iRegionId, sMroomNamee, "", 0, DAddtime, iMroomSeq, "1", smroom_memo, sid);
                }
                catch
                {
                }

                if (iback > 0)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功!');location.href='MachineRoomManage.aspx';</script>");
                    return;
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改失败!');</script>");
                    return;
                }
            }
        }
        catch (Exception ex)
        {
            Message.AlertMsg(this, "保存失败");
        }


    }
    #endregion
}

